import { InputQuestion, QuestionBase, TimeQuestion, SelectQuestion, RadioQuestion, TextQuestion, TextTable, TableBase, CustomTableQuestion } from '@/components/public-template';
import { regExp } from '@/utils/regExp';

class IndexService {
  // 基础信息
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new TextQuestion({
        key: 'billCode',
        label: '单据编号'
      }),
      new TextQuestion({
        key: 'creator',
        label: '创建人ID',
        hide: true
      }),
      new TextQuestion({
        key: 'creatorName',
        label: '创建人'
      }),
      new TextQuestion({
        key: 'department',
        label: '创建部门ID',
        hide: true
      }),
      new TextQuestion({
        key: 'departmentName',
        label: '创建部门'
      }),
      new TextQuestion({
        key: 'createdTime',
        label: '创建时间'
      }),
      new TextQuestion({
        key: 'expirationReminder',
        label: '到期提醒时间'
      })
    ];
    return questions;
  }

  // 档案归还列表（申请）
  getReturnListAddQuestions({ showType }) {
    const questions: QuestionBase<any>[] = [
      new CustomTableQuestion({
        key: 'customTable',
        value: [],
        state: {
          grid: 24,
          fullLine: true,
          isAdd: true,
          scroll: { x: 2500 },
          columns: [
            {
              title: '序号',
              type: 'index'
            },
            {
              title: '归还类型',
              key: 'returnType',
              type: 'select',
              required: true,
              prompt: '请选择',
              options: [
                { label: '正常归还', value: '1' },
                { label: '丢失', value: '0' }
              ]
            },
            {
              title: '逾期原因',
              key: 'overdueReason',
              type: 'input'
            },
            {
              title: '备注',
              key: 'remark',
              type: 'input'
            },
            {
              title: '文件名称',
              key: 'filename',
              type: 'select'
            },
            {
              title: '文件编码',
              key: 'code'
            },
            {
              title: '文件号',
              key: 'fileCode'
            },
            {
              title: '档案编码',
              key: 'filesBoxCode'
            },
            {
              title: '借阅类型',
              key: 'borrowType',
              type: 'dictionary',
              state: {
                filterName: 'DMS_ARCHIVES_FILE_BORROW_BORROW_TYPE'
              }
            },
            {
              title: '档案类型',
              key: 'filesTypeName'
            },
            {
              title: '保密等级',
              key: 'secretLevel',
              type: 'dictionary',
              state: {
                filterName: 'SECRET_LEVEL'
              }
            },
            {
              title: '借阅编码',
              key: 'borrowCode'
            },
            showType === 'UPDATE'
              ? {
                  title: '档案借阅单据编号',
                  key: 'billCode'
                }
              : {
                  title: '档案借阅单据编号',
                  key: 'billCode',
                  type: 'event',
                  state: {
                    type: 'url',
                    url: 'ArchivesManageAddBorrow',
                    params: [{ id: 'billId' }],
                    assign: { showType: 'VIEW' }
                  }
                },
            {
              title: '计划归还时间',
              key: 'planReturnTime'
            },
            {
              title: '实际归还时间',
              key: 'actualReturnTime'
            },
            {
              title: '操作',
              type: 'operation',
              handle: [
                {
                  type: 'delete',
                  text: '删除',
                  class: 'text-primary',
                  params: [{ id: 'id' }]
                }
              ]
            }
          ]
        }
      })
    ];
    return questions;
  }

  // 档案归还列表（详情）
  getReturnListViewQuestions() {
    const tables: TableBase<any>[] = [
      new TextTable({
        value: '序号',
        type: 'index'
      }),
      new TextTable({
        key: ['fileListList', 'name'],
        value: '文件名称'
      }),
      new TextTable({
        key: ['fileListList', 'code'],
        value: '文件编码'
      }),
      new TextTable({
        key: ['fileListList', 'fileCode'],
        value: '文件号'
      }),
      new TextTable({
        key: 'borrowType',
        value: '借阅类型',
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_BORROW_BORROW_TYPE'
        }
      }),
      new TextTable({
        key: ['fileListList', 'filesTypeName'],
        value: '档案类型'
      }),
      new TextTable({
        key: ['fileListList', 'secretLevel'],
        value: '保密等级',
        type: 'dictionary',
        state: {
          filterName: 'SECRET_LEVEL'
        }
      }),
      new TextTable({
        key: ['fileListList', 'filesBoxCode'],
        value: '档案编码'
      }),
      new TextTable({
        key: 'borrowCode',
        value: '借阅编码'
      }),
      new TextTable({
        key: 'billCode',
        value: '借阅单据编号',
        type: 'router',
        state: {
          type: 'url',
          url: 'ArchivesManageAddBorrow',
          params: [{ id: 'billId' }],
          state: {
            assign: { showType: 'VIEW' }
          }
        }
      }),
      new TextTable({
        key: 'planReturnTime',
        value: '计划归还时间'
      }),
      new TextTable({
        key: 'actualReturnTime',
        value: '实际归还时间'
      }),
      new TextTable({
        key: 'returnType',
        value: '归还类型',
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_BORROW_RETURN_TYPE'
        }
      }),
      new TextTable({
        key: 'overdueReason',
        value: '逾期原因'
      }),
      new TextTable({
        key: 'remark',
        value: '备注'
      }),
      new TextTable({
        key: ['fileListList', 'storageLocationCode'],
        value: '存放地点'
      })
    ];
    return tables;
  }

  // 档案归还列表（归还确认）
  getReturnListConfirmQuestions() {
    const tables: TableBase<any>[] = [
      new TextTable({
        value: '序号',
        type: 'index'
      }),
      new TextTable({
        key: ['fileListList', 'name'],
        value: '文件名称'
      }),
      new TextTable({
        key: ['fileListList', 'code'],
        value: '文件编码'
      }),
      new TextTable({
        key: ['fileListList', 'fileCode'],
        value: '文件号'
      }),
      new TextTable({
        key: 'borrowType',
        value: '借阅类型',
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_BORROW_BORROW_TYPE'
        }
      }),
      new TextTable({
        key: ['fileListList', 'filesTypeName'],
        value: '档案类型'
      }),
      new TextTable({
        key: ['fileListList', 'secretLevel'],
        value: '保密等级',
        type: 'dictionary',
        state: {
          filterName: 'SECRET_LEVEL'
        }
      }),
      new TextTable({
        key: ['fileListList', 'filesBoxCode'],
        value: '档案编码'
      }),
      new TextTable({
        key: 'borrowCode',
        value: '借阅编码'
      }),
      new TextTable({
        key: 'billCode',
        value: '借阅单据编号'
      }),
      new TextTable({
        key: 'planReturnTime',
        value: '计划归还时间'
      }),
      new TextTable({
        key: 'actualReturnTime',
        value: '实际归还时间'
      }),
      new TextTable({
        key: 'returnType',
        value: '归还类型',
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_BORROW_RETURN_TYPE'
        }
      }),
      new TextTable({
        key: 'overdueReason',
        value: '逾期原因'
      }),
      new TextTable({
        key: 'remark',
        value: '备注'
      }),
      new TextTable({
        key: ['fileListList', 'storageLocationCode'],
        value: '存放地点'
      }),
      new TextTable({
        key: ['fileListList', 'boxCode'],
        value: '档案盒编码'
      })
    ];
    return tables;
  }

  getCommentQuestions() {
    const questions: QuestionBase<any>[] = [
      new RadioQuestion({
        key: 'applyResult',
        label: '意见',
        required: true,
        prompt: '请选择',
        value: 1,
        options: [
          {
            label: '通过',
            value: 1
          },
          {
            label: '驳回',
            value: 2
          }
        ]
      }),
      new InputQuestion({
        key: 'remark',
        label: '备注',
        type: 'textarea',
        reg: regExp.len100,
        prompt: '长度不可超过100个字符'
      })
    ];
    return questions;
  }
}

export default new IndexService();
